/**
 * 表格数据格式化
 */
(function (window) {
    //定义表格formatter返回的变量
    var txt = '';
    // 基础资料类型
    function formatBasicsTypeTxt(value){
        switch(value){
            case "1":
                txt = '<span class="">客户来源</span>';
                break;
            case "2":
                txt = '<span class="">项目类型</span>';
                break;
            case "3":
                txt = '<span class="">项目状态</span>';
                break;
            default:
                txt = '<span class="text-warning">未知</span>';
        }
        return txt;
    }
    // 格式化 内容过长
    function formatTipsValueTxt(len){
        return function (value) {
            if(!value){
                return null;
            }
            txt = value;
            if(value.length >len){
                txt = '<span layer-tips="'+ value +'">'+ value.substring(0,len)+"..." +'</span>';
            }
            return txt;
        };
    }
    // 显示列表 序号（格式化ID）
    function formatNoTxt(value, row, index, field){
        return index+1;
    }
    function CycleTxt(value, row, index, field){
        txt = value + ' 小时';
        return txt;
    }
    // 查看图片
    function formatPictureTxt(value){
        switch(value){
            case '':
            case null:
            case '[]':
                txt = '';
                break;
            default:
                txt = "<a data-picview=\"" + value + "\" data-index=\"0\">预览图片</a>";
        }
        return txt;
    }
    //数金额
    function replaceNotNumber(hehe)
    {
        var fix_amount=hehe.value;
        var fix_amountTest=/((^[1-9]\d*)|^0)(\.\d{0,2}){0,1}$/;
        if(hehe.value != '' && fix_amountTest.test(fix_amount)==false){
            hehe.value = hehe.value.substr(0, hehe.value.length - 1);
            layer.msg('请输入正确金额');
            return;
        }
    }
    //输出
    window.formatTxt = {
        BasicsTypeTxt:formatBasicsTypeTxt,
        TipsValueTxt:formatTipsValueTxt,
        formatPictureTxt:formatPictureTxt,
        NoTxt:formatNoTxt,
        CycleTxt:CycleTxt,
        replaceNotNumber:replaceNotNumber,
    }
})(window);